package cn.dnui_jzy913.dnuifood_16110100913.Activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import cn.dnui_jzy913.dnuifood_16110100913.Activity.BaseActivity;
import cn.dnui_jzy913.dnuifood_16110100913.R;
import cn.dnui_jzy913.dnuifood_16110100913.bean.upUserBean;
import cn.dnui_jzy913.dnuifood_16110100913.listener.RetrofitListener;
import cn.dnui_jzy913.dnuifood_16110100913.model.UserModel;

public class UpUserXinxiBean extends BaseActivity implements RetrofitListener<upUserBean> {
    private EditText username,userpass,tel,address;
    private Button tijiao;
    private ImageButton fanhui;
    @Override
    protected int initlayout() {
        return R.layout.activity_upuserinfo;
    }

    @Override
    void initViews() {
        username = findViewById(R.id.up_username);
        userpass = findViewById(R.id.up_userpass);
        tel = findViewById(R.id.up_tel);
        address = findViewById(R.id.up_dizhi);
        tijiao = findViewById(R.id.up_btn_tijiao);
        fanhui = findViewById(R.id.up_fanhui);

    }

    @Override
    void initEvents() {
        fanhui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        tijiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                upXingxi();
            }
        });
    }

    public void upXingxi(){
        UserModel userModel = new UserModel();
        userModel.updateUserById(
                getUser_id(),
                username.getText().toString(),
                userpass.getText().toString(),
                tel.getText().toString(),
                address.getText().toString(),this);
    }
    @Override
    void initData() {
        Intent intent = getIntent();
        username.setText(intent.getStringExtra("username"));
        userpass.setText(intent.getStringExtra("userpass"));
        tel.setText(intent.getStringExtra("tel"));
        address.setText(intent.getStringExtra("address"));

    }

    @Override
    public void onSuccess(upUserBean object, int flag) {
        if(object.getSuccess().equals("0")){
            showToast("修改失败");
        }else {
            showToast("修改成功");
            finish();
        }

    }

    @Override
    public void onFalure() {
        showToast("网路错误");
    }
}

